/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mygameframework.core;

import com.mygameframework.core.GameCore;
import com.mygameframework.core.input.InputManager;
import com.mygameframework.scenes.CommonScene;
import com.mygameframework.states.StateMachine;
import java.awt.Graphics2D;

/**
 * 带场景管理screenManager,带输入管理
 * @author bill
 */
public class GeneralGameCore  extends GameCore{
    @Override
    public void init() {
        super.init();
        inputManager=new InputManager(screenManager.getGameWindow());
        createGameActions() ;
        screensMachine=new StateMachine(this);
        //TODO 子类化时,应在init方法加上下行 并设置适合的
//        setScreen(new CommonScene(this));
        
    }

    @Override
    public void update(long elapsedTime) {
//        super.update(elapsedTime);
        // check input that can happen whether paused or not
//        checkSystemInput();

        if (!isPaused()) {
            // check game input
//            checkGameInput();
            screensMachine.update(elapsedTime);
            // update sprite
//            player.update(elapsedTime);
        }
        getInputManager().update(elapsedTime);
    }

    @Override
    public void draw(Graphics2D g) {
        CommonScene scene= (CommonScene) screensMachine.getCurrentState();
        if(scene!=null) scene.draw(g);
        
//        throw new UnsupportedOperationException("Not supported yet.");
    }
    /**
     * 为 场景机 安装当前场景
     * @param s 要安装的场景
     */
    public void setScreen(CommonScene s){
        screensMachine.setCurrentState(s);
    }
    
    /**
        Sets the paused state.
    */
    public void setPaused(boolean p) {
        if (paused != p) {
            this.paused = p;
//            inputManager.resetAllGameActions();
        }
    }
    /**
    Tests whether the game is paused or not.
     */
    public boolean isPaused() {
        return paused;
    }
    public InputManager getInputManager() {
        return inputManager;
    }
    /**
     * init()方法中被调用 
     */
    protected void createGameActions() { }
    //下面两个方法被移至CommonScene中
//    protected void checkGameInput(){} ;
//    protected void checkSystemInput(){} ;
    
    
    protected InputManager inputManager;
    protected StateMachine screensMachine;//场景机
//    protected GameAction jump;
//    protected GameAction exit;
//    protected GameAction moveLeft;
//    protected GameAction moveRight;
//    protected GameAction pause;
    
    private boolean paused=false;
    
//    private Player player;
//    private Image bgImage;
}
